﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Flac2Wma
{
    public partial class FormEncoders : Form
    {
        //
        public static string AAC_Encoder { get; set; }
        public static string AAC_CommandLine { get; set; }
        //
        public static string MP3_Encoder { get; set; }
        public static string MP3_CommandLine { get; set; }
        //
        public class SelectEncodersEventArgs : EventArgs
        {
            public string AAC_Encoder { get; set; }
            public string AAC_CommandLine { get; set; }
            //
            public string MP3_Encoder { get; set; }
            public string MP3_CommandLine { get; set; }
            //
            public SelectEncodersEventArgs(string AAC_Encoder, string AAC_CommandLine, string MP3_Encoder, string MP3_CommandLine)
            {
                this.AAC_Encoder = AAC_Encoder;
                this.AAC_CommandLine = AAC_CommandLine;
                //
                this.MP3_Encoder = MP3_Encoder;
                this.MP3_CommandLine = MP3_CommandLine;
            }
        }
        //
        public delegate void OnDone(SelectEncodersEventArgs e);
        public event OnDone OnSave;
        protected virtual void OnDoneSave(SelectEncodersEventArgs e)
        {
            OnSave(e);
        }
        //
        //
        public FormEncoders()
        {
            InitializeComponent();
            //
            textBox_AAC_Encoder.Multiline = false;
            textBox_AAC_CommandLine.Multiline = false;
            //
            textBox_MP3_Encoder.Multiline = false;
            textBoxMP3_CommandLine.Multiline = false;
            //
        }

        private void FormEncoders_Load(object sender, EventArgs e)
        {
            textBox_AAC_Encoder.Text = AAC_Encoder;
            textBox_AAC_CommandLine.Text = AAC_CommandLine;
            //
            textBox_MP3_Encoder.Text = MP3_Encoder;
            textBoxMP3_CommandLine.Text = MP3_CommandLine;
        }

        private void button_AAC_Search_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;
            openFileDialog1.Multiselect = false;
            openFileDialog1.ValidateNames = true;
            openFileDialog1.ShowReadOnly = true;
            openFileDialog1.FileName = "neroAacEnc.exe";
            //openFileDialog1.AutoUpgradeEnabled = true;
            openFileDialog1.DefaultExt = ".exe";
            openFileDialog1.Filter = "EXE|*.exe";
            //
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {
                textBox_AAC_Encoder.Text = openFileDialog1.FileName;
            }
        }

        private void button_MP3_Search_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;
            openFileDialog1.Multiselect = false;
            openFileDialog1.ValidateNames = true;
            openFileDialog1.ShowReadOnly = true;
            openFileDialog1.FileName = "lame.exe";
            //openFileDialog1.AutoUpgradeEnabled = true;
            openFileDialog1.DefaultExt = ".exe";
            openFileDialog1.Filter = "EXE|*.exe";
            //
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {
                textBox_MP3_Encoder.Text = openFileDialog1.FileName;
            }
        }

        private void button_OK_Click(object sender, EventArgs e)
        {
            AAC_Encoder = textBox_AAC_Encoder.Text.Trim();
            AAC_CommandLine = textBox_AAC_CommandLine.Text.Trim();
            //
            MP3_Encoder = textBox_MP3_Encoder.Text.Trim();
            MP3_CommandLine = textBoxMP3_CommandLine.Text.Trim();
            //
            if (null != OnSave)
            {
                OnDoneSave(new SelectEncodersEventArgs(AAC_Encoder, AAC_CommandLine, MP3_Encoder, MP3_CommandLine));
            }
            this.Close();
        }

        private void button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
